﻿using MP.Data.Models.Models;
using MP.Data.Models.Models.Mapping;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace MP.Data.DbModels
{
    public class MPEntities : DbContext
    {
        static MPEntities()
        {
            Database.SetInitializer<MPEntities>(null);
        }

        public MPEntities()
            : base(GetConnectionString())
        {
            this.Configuration.LazyLoadingEnabled = false;
        }

        private static string GetConnectionString()
        {
            return ConfigurationManager.ConnectionStrings["Smakota"].ConnectionString;
        }

        public DbSet<Measure> Measures { get; set; }
        public DbSet<MeasureAmount> MeasureAmounts { get; set; }
        public DbSet<Food> Foods { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new MeasureMap());
            modelBuilder.Configurations.Add(new MeasureAmountMap());
            modelBuilder.Configurations.Add(new FoodMap());
        }
    }
}
